package com.develop.data.loan.manager.change.amount;

import com.develop.data.loan.manager.change.amount.api.LoanInstallmentAmountClear;
import com.develop.data.loan.model.LoanInstallment;
import org.springframework.stereotype.Component;

import javax.money.MonetaryAmount;
import java.time.LocalDateTime;

@Component("L0001B0001LoanInstallmentPrincipalClear")
public class L0001B0001LoanInstallmentPrincipalClear implements LoanInstallmentAmountClear {

    /* 已发生形态转移 */
    /* 持有时间，左受制于动帐时间，右受制于转非应计时间（不计息） */
    /* LoanInstallmentPrincipalCleared对应Installment的PrincipalCleared金额字段 */
    /* 第M期为当前期，预览第N期 */

    public MonetaryAmount preview(LoanInstallment loanInstallment, LocalDateTime localDate){
        return loanInstallment.getInstallmentPrincipalDueAccrual();
    }

    public void execute(LoanInstallment loanInstallment, LocalDateTime localDate){

        MonetaryAmount amountPreviewed = this.preview(loanInstallment, localDate);
        loanInstallment.setInstallmentPrincipalDueAccrual(loanInstallment.getInstallmentPrincipalDueAccrual().subtract(amountPreviewed));
        loanInstallment.setInstallmentPrincipalCleared(loanInstallment.getInstallmentPrincipalCleared().add(amountPreviewed));

    }

}
